package com.bitBusy.manageyourriches.utilityClasses.display;


import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.bitBusy.manageyourriches.utilityClasses.checkers.NullChecker;
import com.bitBusy.manageyourriches.utilityClasses.dialogboxes.BasicDialogBox;
import com.bitBusy.manageyourriches.utilityClasses.dialogboxes.DialogBoxPrompts;
import com.bitBusy.manageyourriches.utilityClasses.dialogboxes.DialogWithEditText;
import com.bitBusy.manageyourriches.utilityClasses.dialogboxes.DialogWithThreeButtonsOnly;
import com.bitBusy.manageyourriches.utilityClasses.navigation.GoHome;
/**
 * 
 */

/**
 * Class that has methods to display different messages
 * @author SumaHarsha
 *
 */
public class DisplayMessages {

		
	/** Method to display an error message - caused by user
	 * @param the context
	 * @param the error message string*/
	public static void displayUserError(Context the_context, String the_errorMessage)
	{
		if (!NullChecker.checkForNullValues(new Object[]{the_context, the_errorMessage}))
		{
			BasicDialogBox dialog = new BasicDialogBox();
			dialog.set(the_context, DialogBoxPrompts.DIALOGERRORTITLE.getPrompt(),
					the_errorMessage , DialogBoxPrompts.DIALOGOKPROMPT.getPrompt(), 
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog,int id) {
							dialog.cancel();
						};}, null, null, null, null);
			dialog.showDialog();

			
		}
	}
	
	/** Method to display an error message - caused internally
	 * @param the context
	 * @param the error message string*/
	public static void displayInternalError(final Context the_context, String the_errorMessage)
	{
		if (!NullChecker.checkForNullValues(new Object[]{the_context, the_errorMessage}))
		{
			BasicDialogBox dialog = new BasicDialogBox();
			dialog.set(the_context, DialogBoxPrompts.DIALOGERRORTITLE.getPrompt(),
					the_errorMessage , DialogBoxPrompts.DIALOGOKPROMPT.getPrompt(), 
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog,int id) {
							GoHome.goHome(the_context);
						};}, null, null, null, null);
			dialog.showDialog();

			
		}
	}
	
	
	/**
	 * Method to display a dialog box which allows user input
	 * @param the_context context
	 * @param the_caller which implements DisplayInputTextUsers
	 * @param the_title of the dialog box
	 * @param the_message to be displayed in the dialog box
	 * @param the_positiveText on the button
	 * @param the_negativeText on the button
	 */
	public static void displayUserInputTextBoxAndGetInput(Context the_context,final DisplayInputTextUsers the_caller, String the_title, String the_message, 
			String the_positiveText,String the_negativeText)
		{
		if (!NullChecker.checkForNullValues(new Object[]{the_context, the_caller, 
				the_title, the_message,the_positiveText, the_negativeText}))
		{
			final DialogWithEditText dialogBox = new DialogWithEditText();
			dialogBox.set
			(the_context, the_title, the_message, the_positiveText, 
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int id) {
							dialogBox.setText();
							sendTextBackToCaller(the_caller, dialogBox.getText());
						};}, 
					the_negativeText, 
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog,int id) {
						dialog.cancel();
					};}, null, null);
			dialogBox.throwOpen();
			}
		}
	
	
	/** Method to send text back to caller
	 * @param the caller
	 * @param the text to send back*/
	private static void sendTextBackToCaller(DisplayInputTextUsers the_caller, String the_text)
	{
		if (!NullChecker.checkForNullValues(new Object[]{the_caller, the_text}))
		{
			the_caller.getTextFromDialog(the_text);
		}
	}

	/**
	 * Display dialog with three buttons only
	 * @param the_context
	 * @param the_caller
	 * @param the_title
	 * @param the_firstButtonText
	 * @param the_secondButtonText
	 * @param the_thirdButtonText
	 */
	public static void displayDialogWithThreeButtonsOnly(Context the_context,final DisplayButtonValueUsers the_caller, String the_title, 
			String the_firstButtonText,	String the_secondButtonText, String the_thirdButtonText)
		{
		if (the_context != null)
		{
			final DialogWithThreeButtonsOnly dialogBox = new DialogWithThreeButtonsOnly(the_context);
			dialogBox.set
			(the_title, the_firstButtonText, getButtonListener(the_caller, dialogBox), the_secondButtonText, getButtonListener(the_caller, dialogBox),
					the_thirdButtonText, 
					new View.OnClickListener() {
					public void onClick(View the_view) {
						dialogBox.cancel();
					};});
			dialogBox.throwOpen();
		}
	}
	
	public static void displayStandardDialog(Context the_context, String the_title, 
			String the_text, String the_positiveText, DialogInterface.OnClickListener the_positiveListener, String the_negativeText, 
			DialogInterface.OnClickListener the_negativeListener)
		{
		if (the_context != null)
		{
			final BasicDialogBox dialogBox = new BasicDialogBox();
			dialogBox.set(the_context, the_title, the_text, the_positiveText,
					the_positiveListener, the_negativeText,the_negativeListener, null, null);
			dialogBox.showDialog();
		}
	}
	
	
	/**Set listener*/
	private static OnClickListener getButtonListener(final DisplayButtonValueUsers the_caller, final DialogWithThreeButtonsOnly the_dialogBox)
	{
	  return new View.OnClickListener() {
		  @Override
			public void onClick(View the_view) {
			  the_dialogBox.cancel();
				sendButtonClickedBackToCaller(the_caller, the_view);	
				
			}};		
	}

	
	/** Method to send button clicked back to caller
	 * @param the caller
	 * @param the text to send back*/
	private static void sendButtonClickedBackToCaller(DisplayButtonValueUsers the_caller, View the_view)
	{
		if (!NullChecker.checkForNullValues(new Object[]{the_caller, the_view}))
		{
			the_caller.getButtonClickOnDialog((Button) the_view);
		}
	}

}